package com.popay.monitor;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@EnableAdminServer
@EnableDiscoveryClient
@SpringBootApplication
public class popayMonitorApplication {
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(popayMonitorApplication.class, args);
        Environment env = application.getEnvironment();
        String contextPath = env.getProperty("server.servlet.context-path");
        if (contextPath == null) {
            contextPath = "";
        }
        String agreement = env.getProperty("server.ssl.key-store");
        if (agreement == null) {
            agreement = "http";
        } else {
            agreement = "https";
        }
        log.info("\n---------------------------------------------------------\n" +
                "Application '{}' is running! Access URLs:\n\t" +
                "Local: \t\t{}://localhost:{}{}\n\t" +
                "External: \t{}://{}:{}{}\n\t"+
                "knife4j Api Doc: \t{}://{}:{}{}/doc.html\n"+
                "\n---------------------------------------------------------\n",
                env.getProperty("spring.application.name"),
                agreement,env.getProperty("server.port"),contextPath,
                agreement,InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"),contextPath,
                agreement,InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"),contextPath);
    }
}